package com.swust.ipmsg;

import java.util.LinkedList;
import java.util.List;

import com.swust.ipmsg.service.IPmsgService;

import android.app.Activity;
import android.app.Application;
import android.content.Intent;

public class IPMsgApplication extends Application {
	private List<Activity> activities = new LinkedList<Activity>();
	
	public static IPMsgApplication instance;
	
	//之前这里是private，限制了IPMsgApplication建立，会报错
	public IPMsgApplication(){
		
	}
	//单例模式中获取唯一的IPMsgApplication实例
	public static IPMsgApplication getInstance() {
		if (instance == null ) {
			instance = new IPMsgApplication();
		}
		return instance;
	}
	
	/**
	 * 添加Activity到容器中
	 */
	public void addActivity(Activity activity) {
		activities.add(activity);
	}
	
	/**
	 * 遍历所有Activity并finish
	 */
	public void exit() {
		for (Activity activity : activities) {
			activity.finish();
		}
	}
}
